package com.ctgu.project.controller;

import com.ctgu.project.service.UserFollowsService;
import com.ctgu.project.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserFollowsController
 * @Author Alex2
 * @Date 2025/2/27 17:56
 **/

@RestController
@RequestMapping("/api/follows")
public class UserFollowsController {

    @Autowired
    private UserFollowsService userFollowsService;

    /**
     * @Author: Alex
     * @Description: 添加用户(模拟)
     */
    // http://localhost:8080/api/follows/addUsers
    @GetMapping("addUsers")
    public ApiResult addUsers() {
        return userFollowsService.addUsers();
    }

    /**
     * @Author: Alex
     * @Description: 为用户添加粉丝(模拟)
     */
    // http://localhost:8080/api/follows/addFollow
    @GetMapping("addFollow")
    public ApiResult addFollows() {
        return userFollowsService.addFollows();
    }

    /**
     * @Author: Alex
     * @Description: 关注/取关
     */
    // http://localhost:8080/api/follows/follow?userId=1&followId=4
    @GetMapping("/follow")
    public ApiResult follow(@RequestParam Integer userId, @RequestParam Integer followId) {
        return userFollowsService.follow(userId, followId);
    }

    /**
     * @Author: Alex
     * @Description: 获取共同关注
     */
    // http://localhost:8080/api/follows/commons?userId=1&otherUserId=2
    @GetMapping("/commons")
    public ApiResult followCommons(@RequestParam Integer userId, @RequestParam Integer otherUserId) {
        return userFollowsService.commons(userId, otherUserId);
    }

    /**
     * @Author: Alex
     * @Description: 插入博客并将其推送给粉丝
     */
    // http://localhost:8080/api/follows/saveBlog?title=hhhhhhh&userId=1
    @GetMapping("/saveBlog")
    public ApiResult saveBlog(@RequestParam String title, @RequestParam Integer userId) {
        return userFollowsService.insertBlog(title, userId);
    }
}